package pro.survey.analyzer.imp.window;

import java.text.SimpleDateFormat;
import java.util.List;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
import pro.survey.analyzer.HibernateUtil;
import pro.survey.analyzer.data.Imports;

/**
 *
 * @author Adrian
 */
public class ImportList extends ListView<String>{
    
    public ImportList() {
        this.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> ov, 
                String old_val, String new_val) {
                ImportsWindow.getInstance().getButtonOK().setDisable(false);
                ImportsWindow.getInstance().getButtonOK().setSelectedItem(new_val);
        }});
        List<Imports> imports = HibernateUtil.getSession().createQuery(
        "from Imports")
        .list();
        ObservableList<String> items = FXCollections.observableArrayList();
        for (Imports imp : imports) {
            SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            items.add(date.format(imp.getCreated()));
        }
        this.setItems(items);
    }
}
